package domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "books")
@NamedQueries({
	@NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b")
})
public class Book {
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	@Column(name = "id", nullable = false)
	private int id;
	@ManyToOne()
	@JoinColumn(name = "class_id", nullable = false)
	private BookClass bookClass;
	
	public Book() {}

	
	
	public Book(int id, BookClass bookClass) {
		super();
		this.id = id;
		this.bookClass = bookClass;
	}



	public Book(BookClass bookClass) {
		this.bookClass = bookClass;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public BookClass getBookClass() {
		return bookClass;
	}

	public void setBookClass(BookClass bookClass) {
		this.bookClass = bookClass;
	}

	@Override
	public String toString() {
		return "Book id=" + id + " bookClass: " + bookClass.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((bookClass == null) ? 0 : bookClass.hashCode());
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Book other = (Book) obj;
		if (bookClass == null) {
			if (other.bookClass != null)
				return false;
		} else if (!bookClass.equals(other.bookClass))
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	
}
